Skip to content

fix(ui): eliminate N+1 reactive subscriptions in SessionTurn#18924

Merged
adamdotdevin merged 2 commits intoanomalyco:devfrom
BYK:byk/fix-session-turn-n1
Mar 24, 2026
Merged

fix(ui): eliminate N+1 reactive subscriptions in SessionTurn#18924
adamdotdevin merged 2 commits intoanomalyco:devfrom
BYK:byk/fix-session-turn-n1

Conversation

@BYK
Copy link
Copy Markdown
Contributor

@BYK BYK commented Mar 24, 2026

Issue for this PR

Closes #18920

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Every SessionTurn instance creates its own subscription to data.store.message[sessionID]. For N rendered turns, there are N subscriptions to the same store path. Every message update triggers ALL N memos to re-derive, cascading through messageIndex, message, assistantMessages, assistantVisible, assistantTailVisible, and reasoningHeading. During streaming on long sessions this freezes the browser.

Adds an optional messages prop to SessionTurn so the parent MessageTimeline can pass the computed allMessages array. This replaces N store subscriptions with a single subscription in the parent. Falls back to the existing store subscription when the prop is absent (backwards compatible with the enterprise share page).

Also replaces JSON.stringify equality check in the comments memo with structural field comparison.

How did you verify your code works?

  • bun test passes for packages/ui (5/5) and packages/app (291/291)
  • TypeScript typechecks clean for packages/ui

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Add optional messages prop to SessionTurn so the parent MessageTimeline
can pass the computed allMessages array. This replaces N store
subscriptions (one per rendered turn) with a single subscription in the
parent. Falls back to the existing store subscription when the prop is
absent (backwards compatible with enterprise share page).

Also replaces JSON.stringify equality check in the comments memo with
structural field comparison.
@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title perf(ui): eliminate N+1 reactive subscriptions in SessionTurn doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 24, 2026
@BYK BYK changed the title perf(ui): eliminate N+1 reactive subscriptions in SessionTurn fix(ui): eliminate N+1 reactive subscriptions in SessionTurn Mar 24, 2026
@github-actions github-actions Bot removed needs:title needs:compliance This means the issue will auto-close after 2 hours. labels Mar 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Replace three independent memos (assistantVisible, assistantTailVisible,
reasoningHeading) that each iterate all assistant messages and parts with
a single-pass computation. One turn had 106 assistant messages / 411
parts — three memos created 3x106 store subscriptions and ~1200 part
evaluations per reactive cycle.
@adamdotdevin adamdotdevin merged commit c9c93ea into anomalyco:dev Mar 24, 2026
9 checks passed
Andres77872 pushed a commit to Andres77872/opencode that referenced this pull request Mar 26, 2026
dzianisv pushed a commit to dzianisv/opencode that referenced this pull request Mar 26, 2026
dzianisv pushed a commit to dzianisv/opencode that referenced this pull request Apr 2, 2026
balcsida pushed a commit to balcsida/opencode that referenced this pull request Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SessionTurn N+1 reactive subscriptions cause browser slowdown on long sessions

2 participants